package com.teamit.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.teamit.entity.Document;
import com.teamit.entity.Project;
import com.teamit.service.DocumentService;
import com.teamit.util.StringUtil;
import com.teamit.util.db.Page;
import com.teamit.util.web.ServletUtil;

public class DocumentServlet extends HttpServlet {

	
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String p = request.getParameter("p");
		
		int pageNum = 1;
		if(StringUtil.isNotEmpty(p)) {
			try {
				pageNum = Integer.parseInt(p);
			} catch (NumberFormatException e) {
				e.printStackTrace();
			}
		}
		Project project = (Project) request.getSession().getAttribute("project");
		//System.out.println(pageNum);
		//System.out.println(project.getId());
		Page<Document> documentList = new DocumentService().findByPageAndProjectId(pageNum,project.getId());
		
		request.setAttribute("documentList", documentList);
		ServletUtil.forword(request, response, "document");
	}

}
